package org.hilo.boot.mybatis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;

/**
 * 插件基类，用于属性配置 设计成抽象类主要是用于后期可扩展，共享参数配置。
 *
 * @author zollty
 * @since 2018-3-16
 */
public abstract class AbstractGenerateMojo {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    private static final String NULL_STR = "null";
    /**
     * 全局配置
     */
//    @Parameter(required = true)
    private StandGlobalConfig global;

	/**
	 * 数据源配置
	 */
//	@Parameter(required = true)
	private DataSourceConfig dataSource;

	/**
	 * 数据库表配置
	 */
//	@Parameter
	private StandStrategyConfig strategy;

	/**
	 * 包 相关配置
	 */
//	@Parameter
	private StandPackageConfig packageInfo;

	/**
	 * 模板 相关配置
	 */
//	@Parameter
	private StandTemplateConfig template;

	protected ConfigBuilder config;

	/**
	 * 初始化配置
	 */
	protected void initConfig() {
        if (null == config) {
            if (global == null) {
                global = new StandGlobalConfig();
            }
            if (strategy == null) {
                strategy = new StandStrategyConfig();
            }
            if (template == null) {
                template = new StandTemplateConfig();
            }
            if (NULL_STR.equalsIgnoreCase(global.getEntityName())) {
                global.setEntityName(null);
            }
            if (NULL_STR.equalsIgnoreCase(template.getXml())) {
                template.setXml(null);
            }
            config = new ConfigBuilder(packageInfo, dataSource, strategy, template, global);
        }
	}

    /**
     * @return the global
     */
    public StandGlobalConfig getGlobal() {
        return global;
    }

    /**
     * @param global the global to set
     */
    public void setGlobal(StandGlobalConfig global) {
        this.global = global;
    }

    /**
     * @return the dataSource
     */
    public DataSourceConfig getDataSource() {
        return dataSource;
    }

    /**
     * @param dataSource the dataSource to set
     */
    public void setDataSource(DataSourceConfig dataSource) {
        this.dataSource = dataSource;
    }

    /**
     * @return the strategy
     */
    public StandStrategyConfig getStrategy() {
        return strategy;
    }

    /**
     * @param strategy the strategy to set
     */
    public void setStrategy(StandStrategyConfig strategy) {
        this.strategy = strategy;
    }

    /**
     * @return the packageInfo
     */
    public StandPackageConfig getPackageInfo() {
        return packageInfo;
    }

    /**
     * @param packageInfo the packageInfo to set
     */
    public void setPackageInfo(StandPackageConfig packageInfo) {
        this.packageInfo = packageInfo;
    }

    /**
     * @return the template
     */
    public StandTemplateConfig getTemplate() {
        return template;
    }

    /**
     * @param template the template to set
     */
    public void setTemplate(StandTemplateConfig template) {
        this.template = template;
    }

}
